package com.xuecheng.service;

import com.xuecheng.dto.QueryMediaParamsDTO;
import com.xuecheng.dto.UploadFileParamsDTO;
import com.xuecheng.model.PageParams;
import com.xuecheng.model.PageResult;
import com.xuecheng.model.RestResponse;
import com.xuecheng.po.MediaFiles;
import com.xuecheng.vo.UploadFileResultVO;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;

/**
 * 媒资文件管理业务类
 */

public interface MediaFileService {
	
	/**
	 * 媒资文件查询方法
	 */
	PageResult<MediaFiles> queryMediaFiels(Long companyId, PageParams pageParams,
	                                       QueryMediaParamsDTO queryMediaParamsDTO);
	
	
	/**
	 * 上传文件的通用接口
	 */
	UploadFileResultVO uploadFile(Long companyId, byte[] bytes, UploadFileParamsDTO uploadFileParamsDTO,
	                              String folder, String objectName);
	
	/**
	 * 将文件信息入库
	 */
	@Transactional
	MediaFiles addMediaFilesToDb(Long companyId, String fileId, UploadFileParamsDTO uploadFileParamsDTO,
	                             String bucket, String objectName);
	
	/**
	 * 检查文件是否存在
	 */
	RestResponse<Boolean> checkFile(String fileMd5);
	
	/**
	 * 检查分块是否存在
	 */
	RestResponse<Boolean> checkChunk(String fileMd5, int chunkIndex);
	
	/**
	 * 上传分块
	 */
	RestResponse<Boolean> uploadChunk(String fileMd5, int chunk, byte[] bytes);
	
	
	/**
	 * 合并分块
	 */
	RestResponse<Boolean> mergechunks(Long companyId, String fileMd5, int chunkTotal,
	                                  UploadFileParamsDTO uploadFileParamsDTO);
	
	/**
	 * 根据id查询文件信息
	 */
	MediaFiles getFileById(String id);
	
	//根据桶和文件路径从minio下载文件
	File downloadFileFromMinIO(File file, String bucket, String objectName);
	
	void addMediaFilesToMinIO(String filePath, String bucket, String objectName);
}
